package com.example.designpattern.responsibility_two.validator;

import com.example.designpattern.responsibility_two.AbstractValidator;
import com.example.model.GoodsDTO;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 价格校验
 *
 * @author long
 * @date 2024/4/20 10:43
 */
//@Service
public class PriceValidator extends AbstractValidator {

    @Override
    public void doValidate(GoodsDTO dto) {

        if(dto.getPrice().compareTo(BigDecimal.ZERO) <= 0){
            throw new RuntimeException("商品价格必须大于0");
        }
    }

    @Override
    protected void preValidate(GoodsDTO dto) {
        logger.info("----------商品价格校验开始----------");
    }

    @Override
    protected void postValidate(GoodsDTO dto) {
        logger.info("----------商品价格校验结束----------");
    }

    @Override
    public int getOrder() {
        return 2;
    }
}
